<template>
  <div class="pagestyle">
    <list_controller :noprintDownShow="true"
      ref="zujianname"
      :options="state.optionsList"
      @yinyong="yinyong1"
      pageName=""
    >
      <template v-slot:opraCurdBtnAll>
        <span v-if="userStore.modify"
          :class="state.addModal ? 'listInfoBtn active' : 'listInfoBtn'"
          @click="addBtn('mul')"
        >
          <svg-icon
            :class="state.addModal ? 'active' : ''"
            class-name="search-icon"
            icon-class="xinzeng"
          />
          新增
        </span>
        <span v-if="userStore.modify" :class="'listInfoBtn'" @click="deleteBtn('mul')">
          <svg-icon class-name="search-icon" icon-class="shanchu" />
          删除
        </span>
      </template>
      <template v-slot:selectNamelist>
        <el-radio-group v-model="state.tabNameData" @change="tabChange">
          <el-radio-button
            v-for="item in state.optionsList.tabList"
            :label="item.name"
            :value="item.tabIndex"
            :key="item"
          />
        </el-radio-group>
      </template>
      <template v-slot:expandFixed="row">
        <div class="expand-wrapper" v-if="row.row.row.sensorSimulateChildList">
          <vxe-table border :data="row.row.row.sensorSimulateChildList">
            <vxe-column
              v-for="(item, index) in state.optionsList.subtableheads"
              :field="item.field"
              :title="item.title"
              :params="{ name: item.name }"
              :width="item.width ? item.width : ''"
              :key="index"
            >
            </vxe-column>
          </vxe-table>
        </div>
        <div class="expand-wrapper" v-if="row.row.row.sensorSwitchChildList">
          <vxe-table border :data="row.row.row.sensorSwitchChildList">
            <vxe-column
              v-for="(item, index) in state.optionsList.subtableheads"
              :field="item.field"
              :title="item.title"
              :params="{ name: item.name }"
              :width="item.width ? item.width : ''"
              :key="index"
            >
            </vxe-column>
          </vxe-table>
        </div>
        <div class="expand-wrapper" v-if="row.row.row.sensorAddChildList">
          <vxe-table border :data="row.row.row.sensorAddChildList">
            <vxe-column
              v-for="(item, index) in state.optionsList.subtableheads"
              :field="item.field"
              :title="item.title"
              :params="{ name: item.name }"
              :width="item.width ? item.width : ''"
              :key="index"
            >
            </vxe-column>
          </vxe-table>
        </div>
      </template>
      <template v-slot:opraCurdBtnlist="row">
        <span>
          <el-button
            type="primary"
            link
            size="small"
            @click="editBtn(row.row.row)"
            >编辑</el-button
          >
          <el-button
            type="primary"
            :disabled="row.row.row.refStatus == '已引用'"
            link
            size="small"
            @click="deleteBtn(row.row.row)"
            >删除</el-button
          >
        </span>
      </template>
      <template v-slot:listSS="{ row, field }">
        <el-tag
          type="success"
          v-if="row.refStatus == '已引用'"
          @click="yinyong(row)"
          >{{ row.refStatus }}</el-tag
        >
        <el-tag v-else>{{ row.refStatus }}</el-tag>
      </template>
    </list_controller>
    <!-- 新增弹框模拟量 -->
    <teleport to="body">
      <vxe-modal
        esc-closable
        destroy-on-close
        :lock-view="false"
        :width="1347"
        :height="auto"
        v-model="state.addModal"
        resize
        :mask="true"
        showFooter
      >
        <template #title>
          <div class="w100 h100 fsc mask_title">{{ state.modalTitle }}</div>
        </template>
        <template #default>
          <div class="form_box">
            <el-form
              ref="formRef"
              :model="state.formData"
              :rules="state.rules"
              label-position="top"
            >
              <div v-if="state.tabName == 'simulate'">
                <el-row :gutter="20">
                  <el-col :span="7">
                    <el-form-item label="名称" prop="sensorName">
                      <el-input
                        clearable
                        v-model="state.formData.sensorName"
                        placeholder="请输入"
                      >
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7">
                    <el-form-item label="主索引" prop="primaryIndexId">
                      <el-input
                        clearable
                        oninput="value=value.replace(/[^\d]/g,'')"
                        v-model="state.formData.primaryIndexId"
                        placeholder="请输入"
                      >
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <!-- <el-col :span="7">
                                        <el-form-item label="子索引" prop="hasChild">
                                            <el-switch v-model="state.formData.hasChild" @change="hasChildChange" />
                                        </el-form-item>
                                    </el-col> -->
                  <!-- <el-col :span="6" v-if="!state.formData.hasChild">
                                        <el-form-item label="单位" prop="sensorUnit">
                                            <el-input clearable v-model="state.formData.sensorUnit" placeholder="请输入">
                                            </el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="6" v-if="!state.formData.hasChild">
                                        <el-form-item label="低量程">
                                            <div class="inputrange fbc">
                                                <el-input oninput="value =value.replace(/[^\-\d.]/g, '') .replace(/^\./g, '').replace(/\.{2,}/g,
'.').replace(/(\.\d+)\./g, '$1') .replace(/(-)\./g, '$1') .replace(/\-{2,}/g, '-')
.replace(/(\d+|\.)-/g, '$1') .replace(/-(0){2,}/g,'$1') .replace(/(-)0+(\d+)/g, '$1$2')
.replace(/^0+(\d)/, '$1') .replace(/(\d{8})\d*/, '$1') .replace(/(\.\d{2})\d*/, '$1')
" clearable v-model.number="state.formData.lowScaleDown" placeholder="请输入">
                                                </el-input>
                                                <span>-</span>
                                                <el-input oninput="value =value.replace(/[^\-\d.]/g, '') .replace(/^\./g, '').replace(/\.{2,}/g,
'.').replace(/(\.\d+)\./g, '$1') .replace(/(-)\./g, '$1') .replace(/\-{2,}/g, '-')
.replace(/(\d+|\.)-/g, '$1') .replace(/-(0){2,}/g,'$1') .replace(/(-)0+(\d+)/g, '$1$2')
.replace(/^0+(\d)/, '$1') .replace(/(\d{8})\d*/, '$1') .replace(/(\.\d{2})\d*/, '$1')" clearable
                                                    v-model.number="state.formData.lowScaleUp" placeholder="请输入">
                                                </el-input>
                                            </div>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="6" v-if="!state.formData.hasChild">
                                        <el-form-item label="高量程">
                                            <div class="inputrange fbc">
                                                <el-input oninput="value =value.replace(/[^\-\d.]/g, '') .replace(/^\./g, '').replace(/\.{2,}/g,
'.').replace(/(\.\d+)\./g, '$1') .replace(/(-)\./g, '$1') .replace(/\-{2,}/g, '-')
.replace(/(\d+|\.)-/g, '$1') .replace(/-(0){2,}/g,'$1') .replace(/(-)0+(\d+)/g, '$1$2')
.replace(/^0+(\d)/, '$1') .replace(/(\d{8})\d*/, '$1') .replace(/(\.\d{2})\d*/, '$1')" clearable
                                                    v-model.number="state.formData.highScaleDown" placeholder="请输入">
                                                </el-input>
                                                <span>-</span>
                                                <el-input oninput="value =value.replace(/[^\-\d.]/g, '') .replace(/^\./g, '').replace(/\.{2,}/g,
'.').replace(/(\.\d+)\./g, '$1') .replace(/(-)\./g, '$1') .replace(/\-{2,}/g, '-')
.replace(/(\d+|\.)-/g, '$1') .replace(/-(0){2,}/g,'$1') .replace(/(-)0+(\d+)/g, '$1$2')
.replace(/^0+(\d)/, '$1') .replace(/(\d{8})\d*/, '$1') .replace(/(\.\d{2})\d*/, '$1')" clearable
                                                    v-model.number="state.formData.highScaleUp" placeholder="请输入">
                                                </el-input>
                                            </div>
                                        </el-form-item>
                                    </el-col> -->
                  <el-col :span="24">
                    <p class="mask_sub_title fbc">
                      <span>
                        <svg-icon
                          class-name="search-icon"
                          icon-class="biaotitubiao"
                        />子索引</span
                      >
                      <el-button type="primary" @click="childAddClick" link>
                        <Plus />新增</el-button
                      >
                    </p>
                  </el-col>
                  <el-row
                    :gutter="20"
                    style="padding: 0 10px; display: flex; align-items: center"
                    v-for="(item, index) in state.formData
                      .sensorSimulateChildList"
                    :key="index"
                  >
                    <el-col :span="3">
                      <el-form-item
                        :label="index == 0 ? '编号' : ''"
                        :prop="`sensorSimulateChildList[${index}]childIndexId`"
                        :rules="state.rules.field_childIndexId"
                      >
                        <el-input
                          style="width: 160px"
                          oninput="value=value.replace(/[^\d.]/g,'')"
                          clearable
                          v-model.number="item.childIndexId"
                          @change="
                            checkIndex(
                              item.childIndexId,
                              index,
                              state.formData.sensorSimulateChildList
                            )
                          "
                          placeholder="请输入"
                        >
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item
                        :label="index == 0 ? '名称' : ''"
                        :prop="`sensorSimulateChildList[${index}]childIndexName`"
                        :rules="state.rules.field_childIndexName"
                      >
                        <el-input
                          clearable
                          style="width: 160px"
                          v-model="item.childIndexName"
                          placeholder="请输入"
                        >
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item :label="index == 0 ? '单位' : ''" 
                      :prop="`sensorSimulateChildList[${index}]sensorUnit`"
                      :rules="state.rules.field_sensorUnit">
                        <el-input
                          style="width: 160px"
                          clearable
                          v-model="item.sensorUnit"
                          placeholder="请输入"
                        >
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item :label="index == 0 ? '低量程' : ''">
                        <div class="inputrange fbc">
                          <el-input
                            clearable
                            oninput="value =value.replace(/[^\-\d.]/g, '') .replace(/^\./g, '').replace(/\.{2,}/g,
'.').replace(/(\.\d+)\./g, '$1') .replace(/(-)\./g, '$1') .replace(/\-{2,}/g, '-')
.replace(/(\d+|\.)-/g, '$1') .replace(/-(0){2,}/g,'$1') .replace(/(-)0+(\d+)/g, '$1$2')
.replace(/^0+(\d)/, '$1') .replace(/(\d{8})\d*/, '$1') .replace(/(\.\d{2})\d*/, '$1')"
                            @blur="handleInput(item, 'lowScaleDown')"
                            v-model="item.lowScaleDown"
                            placeholder="下限"
                          >
                          </el-input>
                          <span>-</span>
                          <el-input
                            @blur="
                              handleInput(item, 'lowScaleDown', 'lowScaleUp')
                            "
                            clearable
                            oninput="value =value.replace(/[^\-\d.]/g, '') .replace(/^\./g, '').replace(/\.{2,}/g,
'.').replace(/(\.\d+)\./g, '$1') .replace(/(-)\./g, '$1') .replace(/\-{2,}/g, '-')
.replace(/(\d+|\.)-/g, '$1') .replace(/-(0){2,}/g,'$1') .replace(/(-)0+(\d+)/g, '$1$2')
.replace(/^0+(\d)/, '$1') .replace(/(\d{8})\d*/, '$1') .replace(/(\.\d{2})\d*/, '$1')"
                            v-model="item.lowScaleUp"
                            placeholder="上限"
                          >
                          </el-input>
                        </div>
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item :label="index == 0 ? '低量程频率' : ''">
                        <div class="inputrange fbc">
                          <el-input
                            @blur="handleInput(item, 'lowFrequencyDown')"
                            clearable
                            oninput="value =value.replace(/[^\-\d.]/g, '') .replace(/^\./g, '').replace(/\.{2,}/g,
'.').replace(/(\.\d+)\./g, '$1') .replace(/(-)\./g, '$1') .replace(/\-{2,}/g, '-')
.replace(/(\d+|\.)-/g, '$1') .replace(/-(0){2,}/g,'$1') .replace(/(-)0+(\d+)/g, '$1$2')
.replace(/^0+(\d)/, '$1') .replace(/(\d{8})\d*/, '$1') .replace(/(\.\d{2})\d*/, '$1')"
                            v-model="item.lowFrequencyDown"
                            placeholder="下限"
                          >
                          </el-input>
                          <span>-</span>
                          <el-input
                            @blur="
                              handleInput(
                                item,
                                'lowFrequencyDown',
                                'lowFrequencyUp'
                              )
                            "
                            clearable
                            oninput="value =value.replace(/[^\-\d.]/g, '') .replace(/^\./g, '').replace(/\.{2,}/g,
'.').replace(/(\.\d+)\./g, '$1') .replace(/(-)\./g, '$1') .replace(/\-{2,}/g, '-')
.replace(/(\d+|\.)-/g, '$1') .replace(/-(0){2,}/g,'$1') .replace(/(-)0+(\d+)/g, '$1$2')
.replace(/^0+(\d)/, '$1') .replace(/(\d{8})\d*/, '$1') .replace(/(\.\d{2})\d*/, '$1')"
                            v-model="item.lowFrequencyUp"
                            placeholder="上限"
                          >
                          </el-input>
                        </div>
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item :label="index == 0 ? '高量程' : ''">
                        <div class="inputrange fbc">
                          <el-input
                            @blur="
                              handleInput(item, 'highScaleUp', 'highScaleDown')
                            "
                            clearable
                            oninput="value =value.replace(/[^\-\d.]/g, '') .replace(/^\./g, '').replace(/\.{2,}/g,
'.').replace(/(\.\d+)\./g, '$1') .replace(/(-)\./g, '$1') .replace(/\-{2,}/g, '-')
.replace(/(\d+|\.)-/g, '$1') .replace(/-(0){2,}/g,'$1') .replace(/(-)0+(\d+)/g, '$1$2')
.replace(/^0+(\d)/, '$1') .replace(/(\d{8})\d*/, '$1') .replace(/(\.\d{2})\d*/, '$1')"
                            v-model="item.highScaleDown"
                            placeholder="下限"
                          >
                          </el-input>
                          <span>-</span>
                          <el-input
                            @blur="
                              handleInput(item, 'highScaleDown', 'highScaleUp')
                            "
                            clearable
                            oninput="value =value.replace(/[^\-\d.]/g, '') .replace(/^\./g, '').replace(/\.{2,}/g,
'.').replace(/(\.\d+)\./g, '$1') .replace(/(-)\./g, '$1') .replace(/\-{2,}/g, '-')
.replace(/(\d+|\.)-/g, '$1') .replace(/-(0){2,}/g,'$1') .replace(/(-)0+(\d+)/g, '$1$2')
.replace(/^0+(\d)/, '$1') .replace(/(\d{8})\d*/, '$1') .replace(/(\.\d{2})\d*/, '$1')"
                            v-model="item.highScaleUp"
                            placeholder="上限"
                          >
                          </el-input>
                        </div>
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item :label="index == 0 ? '高量程频率' : ''">
                        <div class="inputrange fbc">
                          <el-input
                            @blur="
                              handleInput(
                                item,
                                'highFrequencyUp',
                                'highFrequencyDown'
                              )
                            "
                            clearable
                            oninput="value =value.replace(/[^\-\d.]/g, '') .replace(/^\./g, '').replace(/\.{2,}/g,
'.').replace(/(\.\d+)\./g, '$1') .replace(/(-)\./g, '$1') .replace(/\-{2,}/g, '-')
.replace(/(\d+|\.)-/g, '$1') .replace(/-(0){2,}/g,'$1') .replace(/(-)0+(\d+)/g, '$1$2')
.replace(/^0+(\d)/, '$1') .replace(/(\d{8})\d*/, '$1') .replace(/(\.\d{2})\d*/, '$1')"
                            v-model="item.highFrequencyDown"
                            placeholder="下限"
                          >
                          </el-input>
                          <span>-</span>
                          <el-input
                            @blur="
                              handleInput(
                                item,
                                'highFrequencyDown',
                                'highFrequencyUp'
                              )
                            "
                            clearable
                            oninput="value =value.replace(/[^\-\d.]/g, '') .replace(/^\./g, '').replace(/\.{2,}/g,
'.').replace(/(\.\d+)\./g, '$1') .replace(/(-)\./g, '$1') .replace(/\-{2,}/g, '-')
.replace(/(\d+|\.)-/g, '$1') .replace(/-(0){2,}/g,'$1') .replace(/(-)0+(\d+)/g, '$1$2')
.replace(/^0+(\d)/, '$1') .replace(/(\d{8})\d*/, '$1') .replace(/(\.\d{2})\d*/, '$1')"
                            v-model="item.highFrequencyUp"
                            placeholder="上限"
                          >
                          </el-input>
                        </div>
                      </el-form-item>
                    </el-col>
                    <el-col :span="2" v-if="state.editId && item.refStatus">
                      <el-tag
                        type="success"
                        v-if="item.refStatus == '已引用'"
                        @click="
                          yinyong2(
                            state.formData.primaryIndexId,
                            item.childIndexId
                          )
                        "
                      >
                        {{ item.refStatus }}</el-tag
                      >
                      <el-tag v-else>{{ item.refStatus }}</el-tag>
                    </el-col>
                    <el-col :span="1">
                      <!-- <svg-icon  v-if="item.refStatus == '已引用'" style="fill:rgba(227, 60, 100, 1);" 
                      icon-class="mianxingshanchu" /> -->
                      <svg-icon
                        v-if="item.refStatus != '已引用'"
                        class-name="search-icon"
                        icon-class="mianxingshanchu"
                        @click="delchaildIndexClick(index)"
                      />
                    </el-col>
                  </el-row>
                </el-row>
              </div>
              <div v-if="state.tabName == 'switch'">
                <el-row :gutter="20">
                  <el-col :span="6">
                    <el-form-item label="名称" prop="sensorName">
                      <el-input
                        clearable
                        v-model="state.formData.sensorName"
                        placeholder="请输入"
                      >
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="主索引" prop="primaryIndexId">
                      <el-input
                        clearable
                        oninput="value=value.replace(/[^\d]/g,'')"
                        v-model="state.formData.primaryIndexId"
                        placeholder="请输入"
                      >
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="子索引" prop="hasChild">
                      <el-switch
                        v-model="state.formData.hasChild"
                        @click="hasChildChange"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="6" v-if="!state.formData.hasChild">
                    <el-form-item label="开关量模式">
                      <el-select
                        clearable
                        filterable
                        v-model="state.formData.switchModel"
                        placeholder="请选择"
                      >
                        <el-option
                          v-for="item in state.switchModelList"
                          :key="item.code"
                          :label="item.name"
                          :value="item.code"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="6" v-if="!state.formData.hasChild">
                    <el-form-item label="常态逻辑">
                      <el-select
                        clearable
                        filterable
                        v-model="state.formData.normalLogic"
                        placeholder="请选择"
                      >
                        <el-option
                          v-for="item in state.normalLogicList"
                          :key="item.code"
                          :label="item.name"
                          :value="item.code"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="6" v-if="!state.formData.hasChild">
                    <el-form-item label="高电平显示" prop="highShow">
                      <el-input
                        clearable
                        v-model="state.formData.highShow"
                        placeholder="请输入"
                      >
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="6" v-if="!state.formData.hasChild">
                    <el-form-item label="低电平显示" prop="lowShow">
                      <el-input
                        clearable
                        v-model="state.formData.lowShow"
                        placeholder="请输入"
                      >
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="24" v-if="state.formData.hasChild">
                    <p class="mask_sub_title fbc">
                      <span>
                        <svg-icon
                          class-name="search-icon"
                          icon-class="biaotitubiao"
                        />子索引</span
                      >
                      <el-button type="primary" @click="childAddClick" link>
                        <Plus />新增</el-button
                      >
                    </p>
                  </el-col>
                  <el-row
                    v-if="state.formData.hasChild"
                    :gutter="20"
                    style="padding: 0 10px; display: flex; align-items: center"
                    v-for="(item, index) in state.formData
                      .sensorSwitchChildList"
                    :key="index"
                  >
                    <el-col :span="3">
                      <el-form-item
                        :label="index == 0 ? '编号' : ''"
                        :prop="`sensorSwitchChildList[${index}]childIndexId`"
                        :rules="state.rules.field_childIndexId"
                      >
                        <el-input
                          oninput="value=value.replace(/[^\d.]/g,'')"
                          clearable
                          v-model.number="item.childIndexId"
                          @change="
                            checkIndex(
                              item.childIndexId,
                              index,
                              state.formData.sensorSwitchChildList
                            )
                          "
                          placeholder="请输入"
                        >
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item
                        :label="index == 0 ? '名称' : ''"
                        :prop="`sensorSwitchChildList[${index}]childIndexName`"
                        :rules="state.rules.field_childIndexName"
                      >
                        <el-input
                          clearable
                          v-model="item.childIndexName"
                          placeholder="请输入"
                        >
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item :label="index == 0 ? '开关量模式' : ''">
                        <el-select
                          clearable
                          filterable
                          v-model="item.switchModel"
                          placeholder="请选择"
                        >
                          <el-option
                            v-for="item in state.switchModelList"
                            :key="item.code"
                            :label="item.name"
                            :value="item.code"
                          >
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item :label="index == 0 ? '常态逻辑' : ''">
                        <el-select
                          clearable
                          filterable
                          v-model="item.normalLogic"
                          placeholder="请选择"
                        >
                          <el-option
                            v-for="item in state.normalLogicList"
                            :key="item.code"
                            :label="item.name"
                            :value="item.code"
                          >
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item :label="index == 0 ? '高电平显示' : ''">
                        <el-input
                          clearable
                          v-model="item.highShow"
                          placeholder="请输入"
                        >
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item :label="index == 0 ? '低电平显示' : ''">
                        <el-input
                          clearable
                          v-model="item.lowShow"
                          placeholder="请输入"
                        >
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="2" v-if="state.editId">
                      <el-tag
                        type="success"
                        v-if="item.refStatus == '已引用'"
                        @click="
                          yinyong2(
                            state.formData.primaryIndexId,
                            item.childIndexId
                          )
                        "
                      >
                        {{ item.refStatus }}</el-tag
                      >
                      <el-tag v-else>{{ item.refStatus }}</el-tag>
                    </el-col>
                    <el-col :span="1">
                      <!-- <svg-icon  v-if="item.refStatus == '已引用'" style="fill:rgba(227, 60, 100, 1);" icon-class="mianxingshanchu" /> -->
                      <svg-icon
                        v-if="item.refStatus != '已引用'"
                        class-name="search-icon"
                        icon-class="mianxingshanchu"
                        @click="delchaildIndexClick(index)"
                      />
                    </el-col>
                  </el-row>
                </el-row>
              </div>
              <div v-if="state.tabName == 'add'">
                <el-row :gutter="20">
                  <el-col :span="5">
                    <el-form-item label="名称" prop="sensorName">
                      <el-input
                        clearable
                        v-model="state.formData.sensorName"
                        placeholder="请输入"
                      >
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5" v-if="!state.formData.hasChild">
                    <el-form-item label="单位" prop="sensorUnit">
                      <el-input
                        clearable
                        v-model="state.formData.sensorUnit"
                        placeholder="请输入"
                      >
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item label="累计周期" prop="resetType">
                      <el-select
                        clearable
                        v-model="state.formData.resetType"
                        placeholder="请选择"
                      >
                        <el-option
                          v-for="item in state.resetTypeList"
                          :key="item.code"
                          :label="item.name"
                          :value="item.code"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item label="主索引" prop="primaryIndexId">
                      <el-input
                        clearable
                        oninput="value=value.replace(/[^\d]/g,'')"
                        v-model="state.formData.primaryIndexId"
                        placeholder="请输入"
                      >
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4">
                    <el-form-item label="子索引" prop="hasChild">
                      <el-switch
                        v-model="state.formData.hasChild"
                        @change="hasChildChange"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="5" v-if="!state.formData.hasChild">
                    <el-form-item label="累计模式" prop="orderType">
                      <el-select
                        clearable
                        v-model="state.formData.orderType"
                        placeholder="请选择"
                      >
                        <el-option
                          v-for="item in state.orderTypeList"
                          :key="item.code"
                          :label="item.name"
                          :value="item.code"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5" v-if="!state.formData.hasChild">
                    <el-form-item label="起始值" prop="startValue">
                      <el-input
                        oninput="value=value.replace(/[^\d.]/g,'')"
                        clearable
                        v-model="state.formData.startValue"
                        placeholder="请输入"
                      >
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5" v-if="!state.formData.hasChild">
                    <el-form-item label="变化值" prop="changeValue">
                      <el-input
                        oninput="value=value.replace(/[^\d.]/g,'')"
                        clearable
                        v-model="state.formData.changeValue"
                        placeholder="请输入"
                      >
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5" v-if="!state.formData.hasChild">
                    <el-form-item label="上限值" prop="upLimitValue">
                      <el-input
                        oninput="value=value.replace(/[^\d.]/g,'')"
                        clearable
                        v-model="state.formData.upLimitValue"
                        placeholder="请输入"
                      >
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="24" v-if="state.formData.hasChild">
                    <p class="mask_sub_title fbc">
                      <span>
                        <svg-icon
                          class-name="search-icon"
                          icon-class="biaotitubiao"
                        />子索引</span
                      >
                      <el-button type="primary" @click="childAddClick" link>
                        <Plus />新增</el-button
                      >
                    </p>
                  </el-col>
                  <el-row
                    v-if="state.formData.hasChild"
                    :gutter="20"
                    style="padding: 0 10px; display: flex; align-items: center"
                    v-for="(item, index) in state.formData.sensorAddChildList"
                    :key="index"
                  >
                    <el-col :span="3">
                      <el-form-item :label="index == 0 ? '编号' : ''"
                      :prop="`sensorAddChildList[${index}]childIndexId`"
                      :rules="state.rules.field_childIndexId">
                        <el-input
                          oninput="value=value.replace(/[^\d.]/g,'')"
                          clearable
                          v-model.number="item.childIndexId"
                          @change="
                            checkIndex(
                              item.childIndexId,
                              index,
                              state.formData.sensorAddChildList
                            )
                          "
                          placeholder="请输入"
                        >
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item :label="index == 0 ? '名称' : ''"
                      :prop="`sensorAddChildList[${index}]childIndexName`"
                      :rules="state.rules.field_childIndexName">
                        <el-input
                          clearable
                          v-model="item.childIndexName"
                          placeholder="请输入"
                        >
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item :label="index == 0 ? '单位' : ''" 
                      :prop="`sensorAddChildList[${index}]sensorUnit`"
                      :rules="state.rules.field_sensorUnit">
                        <el-input
                          clearable
                          v-model="item.sensorUnit"
                          placeholder="请输入"
                        >
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item :label="index == 0 ? '累计模式' : ''">
                        <el-select
                          clearable
                          v-model="item.orderType"
                          placeholder="请选择"
                        >
                          <el-option
                            v-for="item in state.orderTypeList"
                            :key="item.code"
                            :label="item.name"
                            :value="item.code"
                          >
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item :label="index == 0 ? '起始值' : ''">
                        <el-input
                          oninput="value=value.replace(/[^\d.]/g,'')"
                          clearable
                          v-model="item.startValue"
                          placeholder="请输入"
                        >
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item :label="index == 0 ? '变化值' : ''">
                        <el-input
                          oninput="value=value.replace(/[^\d.]/g,'')"
                          clearable
                          v-model="item.changeValue"
                          placeholder="请输入"
                        >
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item :label="index == 0 ? '上限值' : ''">
                        <el-input
                          oninput="value=value.replace(/[^\d.]/g,'')"
                          clearable
                          v-model="item.upLimitValue"
                          placeholder="请输入"
                        >
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="2" v-if="state.editId">
                      <el-tag
                        type="success"
                        v-if="item.refStatus == '已引用'"
                        @click="
                          yinyong2(
                            state.formData.primaryIndexId,
                            item.childIndexId
                          )
                        "
                      >
                        {{ item.refStatus }}</el-tag
                      >
                      <el-tag v-else>{{ item.refStatus }}</el-tag>
                    </el-col>
                    <el-col :span="1">
                      <!-- <svg-icon  v-if="item.refStatus == '已引用'" style="fill:rgba(227, 60, 100, 1);" icon-class="mianxingshanchu" /> -->
                      <svg-icon
                        v-if="item.refStatus != '已引用'"
                        class-name="search-icon"
                        icon-class="mianxingshanchu"
                        @click="delchaildIndexClick(index)"
                      />
                    </el-col>
                  </el-row>
                </el-row>
              </div>
            </el-form>
          </div>
        </template>
        <template #footer>
          <el-button @click="cancel">取消</el-button>
          <el-button type="primary" @click="submitForm"> 确定 </el-button>
        </template>
      </vxe-modal>
    </teleport>
  </div>
</template>
<script setup>
import list_controller from "@/components/commonCom/list_controller";
import { useRouter } from "vue-router";
import { computed, reactive } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { table_headers } from "@/components/commonCom/table_headers";
import axios from "@/utils/request";
import {
  getsensorName,
} from "@/api/config";
import usePagesStore from "@/store/modules/pages";
import useUserStore from "@/store/modules/user";
const userStore = useUserStore();
const { proxy } = getCurrentInstance();
const store = usePagesStore();
const router = useRouter();
const upload = ref();
const upload1 = ref();
const upload2 = ref();
const validatePass = (rule, value, callback) => {
  let reg = new RegExp(/^\+?[1-9][0-9]*$/);
  if (value == "") {
    return;
  }
  let validParamType = state.options.validParam;
  if (state.tabName == "simulate") {
    validParamType = state.options.validParam;
  } else if (state.tabName == "switch") {
    validParamType = state.options1.validParam;
  } else if (state.tabName == "add") {
    validParamType = state.options2.validParam;
  }
  if (state.editId) {
    axios
      .get(validParamType, {
        params: {
          type: 1,
          value: value,
          id: state.editId,
        },
      })
      .then((res) => {
        if (res.code == 200) {
          state.repeat = false;
          callback();
          if (!reg.test(value)) return callback(new Error("请输入整数"));
        }
      })
      .catch((res) => {
        state.repeat = true;
        return callback(new Error("主索引不能重复"));
      });
  } else {
    axios
      .get(validParamType, {
        params: {
          type: 1,
          value: value,
        },
      })
      .then((res) => {
        console.log(res);
        if (res.code == 200) {
          state.repeat = false;
          callback();
          if (!reg.test(value)) return callback(new Error("请输入整数"));
        }
      })
      .catch((res) => {
        state.repeat = true;
        return callback(new Error("主索引不能重复"));
      });
  }
  // let reg = new RegExp(/^\+?[1-9][0-9]*$/);
  // if(state.repeat){
  //     return callback(new Error("主索引不能重复"));
  // }else{
  //     callback();
  //     if (!reg.test(value))
  //      return callback(new Error("请输入整数"));
  // }
};
const validatePass2 = (rule, value, callback) => {
  let validParamType = state.options.validParam;
  if (state.tabName == "simulate") {
    validParamType = state.options.validParam;
  } else if (state.tabName == "switch") {
    validParamType = state.options1.validParam;
  } else if (state.tabName == "add") {
    validParamType = state.options2.validParam;
  }
  if (state.editId) {
    axios
      .get(validParamType, {
        params: {
          type: 0,
          value: value,
          id: state.editId,
        },
      })
      .then((res) => {
        if (res.code == 200) {
          state.repeat2 = false;
          callback();
        }
      })
      .catch((res) => {
        state.repeat2 = true;
        return callback(new Error("名称不能重复"));
      });
  } else {
    axios
      .get(validParamType, {
        params: {
          type: 0,
          value: value,
        },
      })
      .then((res) => {
        if (res.code == 200) {
          state.repeat2 = false;
          callback();
        }
      })
      .catch((res) => {
        state.repeat2 = true;
        return callback(new Error("名称不能重复"));
      });
  }
};
const validatePass3 = (rule, value, callback) => {
  if (value == "") {
    return;
  }
  if (value == state.formData.lowShow) {
    callback(new Error("高低电平显示不能重复"));
  } else {
    callback();
  }
};
const validatePass4 = (rule, value, callback) => {
  if (value == "") {
    return;
  }
  if (value == state.formData.highShow) {
    callback(new Error("高低电平显示不能重复"));
  } else {
    callback();
  }
};
components: {
  list_controller;
}
let state = reactive({
  nowranDis: false,
  noshangwranDis: false,
  tabNameData: "模拟量",
  optionsList: {},
  options: {
    expandFixed: true,
    tabList: [
      {
        tabIndex: 1,
        name: "模拟量",
      },
      {
        tabIndex: 2,
        name: "开关量",
      },
      {
        tabIndex: 3,
        name: "累计量",
      },
    ],
    tableheads: computed(() => table_headers.specialSimulate),
    subtableheads: computed(() => table_headers.specialSimulateChild),
    listSS: [
      {
        field: "refStatus",
        filterField: {
          field: "refStatus",
          options: [
            {
              label: "已引用",
              value: "已引用",
              checked: false,
            },
            {
              label: "未引用",
              value: "未引用",
              checked: false,
            },
          ],
          sortable: true,
        },
      },
      {
        filterField: {
          field: "primaryIndexId",
          sortable: true,
        },
      },
    ],
    queryList: {
      dropdownUrl: "",
      querys: [
        {
          field: "sensorName",
          title: "名称",
          type: "input",
          binddata: "",
        },
        {
          field: "primaryIndexId",
          title: "主索引",
          type: "input",
          binddata: "",
        },
      ],
      queryMap: new Map([
        ["sensorTypeId", "safety_pointType"],
        ["deviceTypeId", "safety_deviceType"],
        ["alarmTypeId", "alarmType"],
      ]),
    },
    dataUrl: "/sensor/simulate/listSpecial",
    delUrl: "/sensor/simulate/deleteSpecial",
    addUrl: "/sensor/simulate/addSpecial",
    descUrl: "/sensor/simulate/detailSpecial?primaryIndexId=",
    editUrl: "/sensor/simulate/editSpecial",
    validParam: "/sensor/simulate/validParam",
  },
  options1: {
    expandFixed: true,
    tabList: [
      {
        tabIndex: 1,
        name: "模拟量",
      },
      {
        tabIndex: 2,
        name: "开关量",
      },
      {
        tabIndex: 3,
        name: "累计量",
      },
    ],
    tableheads: computed(() => table_headers.specialSwitch),
    subtableheads: computed(() => table_headers.specialSwitchChild),
    listSS: [
      {
        field: "refStatus",
        filterField: {
          field: "refStatus",
          options: [
            {
              label: "已引用",
              value: "已引用",
              checked: false,
            },
            {
              label: "未引用",
              value: "未引用",
              checked: false,
            },
          ],
          sortable: true,
        },
      },
      {
        filterField: {
          field: "primaryIndexId",
          sortable: true,
        },
      },
      {
        filterField: {
          field: "switchModelName",
          options: [
            {
              value: "二态",
              label: "二态",
            },
            {
              value: "三态",
              label: "三态",
            },
          ],
          sortable: true,
        },
      },
      {
        filterField: {
          field: "normalLogicName",
          options: [
            {
              value: "低电平",
              label: "低电平",
            },
            {
              value: "高电平",
              label: "高电平",
            },
          ],
          sortable: true,
        },
      },
    ],
    queryList: {
      dropdownUrl: "",
      querys: [
        {
          field: "sensorName",
          title: "名称",
          type: "input",
          binddata: "",
        },
        {
          field: "primaryIndexId",
          title: "主索引",
          type: "input",
          binddata: "",
        },
      ],
      queryMap: new Map([
        ["sensorTypeId", "safety_pointType"],
        ["deviceTypeId", "safety_deviceType"],
        ["alarmTypeId", "alarmType"],
      ]),
    },
    dataUrl: "/sensor/switch/listSpecial",
    delUrl: "/sensor/switch/deleteSpecial",
    addUrl: "/sensor/switch/addSpecial",
    descUrl: "/sensor/switch/detailSpecial?primaryIndexId=",
    editUrl: "/sensor/switch/editSpecial",
    validParam: "/sensor/switch/validParam",
  },
  options2: {
    expandFixed: true,
    tabList: [
      {
        tabIndex: 1,
        name: "模拟量",
      },
      {
        tabIndex: 2,
        name: "开关量",
      },
      {
        tabIndex: 3,
        name: "累计量",
      },
    ],
    tableheads: computed(() => table_headers.specialAdd),
    subtableheads: computed(() => table_headers.specialAddChild),
    listSS: [
      {
        field: "refStatus",
        filterField: {
          field: "refStatus",
          options: [
            {
              label: "已引用",
              value: "已引用",
              checked: false,
            },
            {
              label: "未引用",
              value: "未引用",
              checked: false,
            },
          ],
          sortable: true,
        },
      },
      {
        filterField: {
          field: "primaryIndexId",
          sortable: true,
        },
      },
      {
        filterField: {
          field: "resetTypeName",
          options: [
            {
              value: "个数",
              label: "个数",
              checked: false,
            },
            {
              value: "小时",
              label: "小时",
            },
            {
              value: "班",
              label: "班",
            },
            {
              value: "天",
              label: "天",
            },
            {
              value: "月",
              label: "月",
            },
            {
              value: "年",
              label: "年",
            },
          ],
          sortable: true,
        },
      },
      {
        filterField: {
          field: "orderTypeName",
          options: [
            {
              value: "递增",
              label: "递增",
            },
            {
              value: "递减",
              label: "递减",
            },
          ],
          sortable: true,
        },
      },
    ],
    queryList: {
      dropdownUrl: "",
      querys: [
        {
          field: "sensorName",
          title: "名称",
          type: "input",
          binddata: "",
        },
        {
          field: "primaryIndexId",
          title: "主索引",
          type: "input",
          binddata: "",
        },
      ],
      queryMap: new Map([
        ["sensorTypeId", "safety_pointType"],
        ["deviceTypeId", "safety_deviceType"],
        ["alarmTypeId", "alarmType"],
      ]),
    },
    dataUrl: "/sensor/add/listSpecial",
    delUrl: "/sensor/add/deleteSpecial",
    addUrl: "/sensor/add/addSpecial",
    descUrl: "/sensor/add/detailSpecial?primaryIndexId=",
    editUrl: "/sensor/add/editSpecial",
    validParam: "/sensor/add/validParam",
  },
  // 表单
  tabName: "simulate",
  addModal: false,
  modalTitle: "新增模拟量",
  formRef: null,
  formData: {},
  locations: [{}],
  rules: {
    sensorName: [
      {
        required: true,
        message: "请输入传感器名称",
        trigger: "blur",
      },
      {
        validator: validatePass2,
        trigger: "blur",
      },
    ],
    sensorUnit: [
      {
        required: true,
        message: "请输入单位",
        trigger: "blur",
      },
    ],
    field_childIndexId: [
      {
        required: true,
        message: "请输入子索引编号",
        trigger: "blur",
      },
    ],
    field_childIndexName: [
      {
        required: true,
        message: "请输入子索引名称",
        trigger: "blur",
      },
    ],
    field_sensorUnit: [
      {
        required: true,
        message: "请输入子索引单位",
        trigger: "blur",
      },
    ],
    primaryIndexId: [
      {
        required: true,
        message: "请输入主索引",
        trigger: "blur",
      },
      {
        validator: validatePass,
        trigger: "blur",
      },
    ],
    switchModel: [
      {
        required: true,
        message: "请选择开关量模式",
        trigger: "change",
      },
    ],
    normalLogic: [
      {
        required: true,
        message: "请选择常态逻辑",
        trigger: "change",
      },
    ],
    highShow: [
      {
        required: true,
        message: "请输入高电平显示",
        trigger: "blur",
      },
      {
        validator: validatePass3,
        trigger: "blur",
      },
    ],
    lowShow: [
      {
        required: true,
        message: "请输入低电平显示",
        trigger: "blur",
      },
      {
        validator: validatePass4,
        trigger: "blur",
      },
    ],
    resetType: [
      {
        required: true,
        message: "请选择累计周期",
        trigger: "change",
      },
    ],
    orderType: [
      {
        required: true,
        message: "请选择累计模式",
        trigger: "change",
      },
    ],
    startValue: [
      {
        required: true,
        message: "请输入起始值",
        trigger: "blur",
      },
    ],
    changeValue: [
      {
        required: true,
        message: "请输入变化值",
        trigger: "blur",
      },
    ],
  },
  editId: undefined,
  resetTypeList: [
    {
      code: 0,
      name: "个数",
    },
    {
      code: 1,
      name: "小时",
    },
    {
      code: 2,
      name: "班",
    },
    {
      code: 3,
      name: "天",
    },
    {
      code: 4,
      name: "月",
    },
    {
      code: 5,
      name: "年",
    },
  ],
  // 下拉数据
  normalLogicList: [
    {
      code: 0,
      name: "低电平",
    },
    {
      code: 1,
      name: "高电平",
    },
  ],
  switchModelList: [
    {
      code: 0,
      name: "二态",
    },
    {
      code: 1,
      name: "三态",
    },
  ],
  orderTypeList: [
    {
      code: 0,
      name: "递增",
    },
    {
      code: 1,
      name: "递减",
    },
  ],
  addeditShow: false,
  repeat: false,
  repeat2: false,
});
// 主索引跳转
const yinyong1 = (row) => {
  router.push({
    path: "/cspz/basicConfig/deviceChara_analog",
    query: {
      primaryIndexId: row.primaryIndexId,
      tabName: state.tabName,
    },
  });
};
// 子索引跳转
const yinyong2 = (pId, id) => {
  router.push({
    path: "/cspz/basicConfig/deviceChara_analog",
    query: {
      primaryIndexId: pId,
      childIndexId: id,
      tabName: state.tabName,
    },
  });
};

// 新增按钮
function addBtn(row) {
  if (state.tabName == "simulate") {
    state.modalTitle = "新增模拟量索引";
    state.formData = {};
    state.formData.hasChild = true;
    state.formData.sensorSimulateChildList = [];
    state.formData.sensorSimulateChildList.push({
      childIndexId: "",
      childIndexName: "",
      highScaleDown: "",
      highScaleUp: "",
      lowFrequencyDown: "",
      lowFrequencyUp: "",
      highFrequencyDown: "",
      highFrequencyUp: "",
      lowScaleDown: "",
      lowScaleUp: "",
    });
  } else if (state.tabName == "switch") {
    state.modalTitle = "新增开关量索引";
    state.formData = {};
  } else if (state.tabName == "add") {
    state.modalTitle = "新增累计量索引";
    state.formData = {};
  }
  state.addModal = true;
  // state.formData = {}
  state.editId = undefined;
  state.addeditShow = true;
}
// 编辑按钮
function editBtn(row) {
  if (state.tabName == "simulate") {
    state.modalTitle = "编辑模拟量索引";
  } else if (state.tabName == "switch") {
    state.modalTitle = "编辑开关量索引";
  } else if (state.tabName == "add") {
    state.modalTitle = "编辑累计量索引";
  }
  state.addModal = true;
  let descUrltype = state.options.descUrl;
  if (state.tabName == "simulate") {
    descUrltype = state.options.descUrl;
  } else if (state.tabName == "switch") {
    descUrltype = state.options1.descUrl;
  } else if (state.tabName == "add") {
    descUrltype = state.options2.descUrl;
  }
  axios.get(descUrltype + row.primaryIndexId).then((res) => {
    if (res.code == 200) {
      if (res.data.sensorSwitchChildList == null) {
        res.data.sensorSwitchChildList = [];
      }
      if (res.data.sensorSimulateChildList == null) {
        res.data.sensorSimulateChildList = [];
      }
      if (res.data.sensorAddChildList == null) {
        res.data.sensorAddChildList = [];
      }
      state.formData = res.data;
      state.editId = res.data.id;
    }
  });
  state.addeditShow = false;
}

function deleteBtn(row) {
  let delUrltype = state.options.delUrl;
  if (state.tabName == "simulate") {
    delUrltype = state.options.delUrl;
  } else if (state.tabName == "switch") {
    delUrltype = state.options1.delUrl;
  } else if (state.tabName == "add") {
    delUrltype = state.options2.delUrl;
  }
  let ids = [];
  if (row != "mul") {
    ids = [row.primaryIndexId];
  } else {
    if (store.records.length > 0) {
      ids = store.records.map((item) => {
        return item.primaryIndexId;
      });
    } else {
      proxy.$modal.msgSuccess("请先勾选所要删除数据!");
    }
  }
  if (ids.length > 0) {
    ElMessageBox.confirm("确定要删除吗?", "温馨提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    })
      .then(() => {
        axios.post(delUrltype, ids).then((res) => {
          if (res.code == 200) {
            proxy.$refs["zujianname"].getData();
            state.addModal = false;
            proxy.$modal.msgSuccess(res.msg);
            store.records = [];
          }
        });
      })
      .catch(() => {
        proxy.$modal.msgWarning("删除取消");
      });
  }
}
// 动态删除行
function delchaildIndexClick(index) {
  if (state.tabName == "simulate") {
    state.formData.sensorSimulateChildList.splice(index, 1);
  } else if (state.tabName == "switch") {
    state.formData.sensorSwitchChildList.splice(index, 1);
  } else if (state.tabName == "add") {
    state.formData.sensorAddChildList.splice(index, 1);
  }
}
// /** 提交按钮 */  /sensor/simulate/validParam
function submitForm() {
  let addUrltype = state.options.addUrl;
  let editUrltype = state.options.editUrl;
  let validParamType = state.options.validParam;
  if (state.tabName == "simulate") {
    addUrltype = state.options.addUrl;
    editUrltype = state.options.editUrl;
  } else if (state.tabName == "switch") {
    addUrltype = state.options1.addUrl;
    editUrltype = state.options1.editUrl;
  } else if (state.tabName == "add") {
    addUrltype = state.options2.addUrl;
    editUrltype = state.options2.editUrl;
  }
  proxy.$refs["formRef"].validate((valid) => {
    if (valid) {
      if (state.editId) {
        if (true) {
          state.formData.id = state.editId;
          // state.formData.sensorSimulateChildList[0].lowFrequencyUp = state.formData.sensorSimulateChildList[0].lowFrequencyUp*1
          axios.post(editUrltype, state.formData).then((res) => {
            if (res.code == 200) {
              proxy.$refs["zujianname"].getData();
              state.addModal = false;
              proxy.$modal.msgSuccess(res.msg);
            }
          });
        }
      } else {
        axios.post(addUrltype, state.formData).then((res) => {
          if (res.code == 200) {
            proxy.$refs["zujianname"].getData();
            state.addModal = false;
            proxy.$modal.msgSuccess(res.msg);
          }
        });
      }
    }
  });
}

function cancel() {
  state.addModal = false;
}

function hasChildChange(val) {
  if (state.addeditShow) {
    if (state.tabName == "simulate") {
      if (val) {
        state.formData.sensorSimulateChildList = [
          {
            childIndexId: "",
            childIndexName: "",
            highScaleDown: "",
            highScaleUp: "",
            lowScaleDown: "",
            lowScaleUp: "",
          },
        ];
      }
    } else if (state.tabName == "switch") {
      if (val) {
        state.formData.sensorSwitchChildList = [
          {
            childIndexId: "",
            childIndexName: "",
            switchModel: "",
            normalLogic: "",
          },
        ];
      }
    } else if (state.tabName == "add") {
      state.formData.sensorAddChildList = [
        {
          childIndexId: "",
          childIndexName: "",
          orderType: "",
          startValue: "",
          changeValue: "",
          upLimitValue: "",
        },
      ];
    }
  } else {
    if (state.tabName == "simulate") {
      if (val) {
        state.formData.sensorSimulateChildList = [
          {
            childIndexId: "",
            childIndexName: "",
            highScaleDown: "",
            highScaleUp: "",
            lowScaleDown: "",
            lowScaleUp: "",
          },
        ];
      }
    } else if (state.tabName == "switch") {
      if (val) {
        state.formData.sensorSwitchChildList = [
          {
            childIndexId: "",
            childIndexName: "",
            switchModel: "",
            normalLogic: "",
          },
        ];
      }
    } else if (state.tabName == "add") {
      state.formData.sensorAddChildList = [
        {
          childIndexId: "",
          childIndexName: "",
          orderType: "",
          startValue: "",
          changeValue: "",
          upLimitValue: "",
        },
      ];
    }
  }
}

function childAddClick() {
  if (state.tabName == "simulate") {
    state.formData.sensorSimulateChildList.push({
      childIndexId: "",
      childIndexName: "",
      highScaleDown: "",
      highScaleUp: "",
      lowFrequencyDown: "",
      lowFrequencyUp: "",
      highFrequencyDown: "",
      highFrequencyUp: "",
      lowScaleDown: "",
      lowScaleUp: "",
    });
  } else if (state.tabName == "switch") {
    state.formData.sensorSwitchChildList.push({
      childIndexId: "",
      childIndexName: "",
      switchModel: "",
      normalLogic: "",
    });
  } else if (state.tabName == "add") {
    state.modalTitle = "新增累计量索引";
    state.formData.sensorAddChildList.push({
      childIndexId: "",
      childIndexName: "",
      orderType: "",
      startValue: "",
      changeValue: "",
      upLimitValue: "",
    });
  }
}

function tabChange(val) {
  state.formData = {};
  state.tabNameData = val;
  if (val == "模拟量") {
    state.optionsList = state.options;
    setTimeout(() => {
      proxy.$refs["zujianname"].getData();
    }, 200);
    getSelectList("simulate");
    state.tabName = "simulate";
    // state.formData.alarmType = state.alarmmodeList[0].code
    state.modalTitle = "新增模拟";
  } else if (val == "开关量") {
    state.optionsList = state.options1;
    setTimeout(() => {
      proxy.$refs["zujianname"].getData();
    }, 200);
    getSelectList("switch");
    state.tabName = "switch";
    // state.formData.alarmType = state.alarmmodeswitchList[0].code
    state.modalTitle = "新增开关";
  } else if (val == "累计量") {
    state.optionsList = state.options2;
    setTimeout(() => {
      proxy.$refs["zujianname"].getData();
    }, 200);
    getSelectList("add");
    state.tabName = "add";
    state.modalTitle = "新增累计";
  }
}

function getSelectList(val) {
  getsensorName(val).then((res) => {
    state.sensorNameList = res.data;
  });
}
state.optionsList = state.options;
getSelectList("simulate");

function alarmTypeChange(val) {
  if (val == 0) {
    state.nowranDis = true;
    state.noshangwranDis = true;
  } else if (val == 1) {
    state.nowranDis = false;
    state.noshangwranDis = true;
  } else {
    state.nowranDis = false;
    state.noshangwranDis = false;
  }
}
// 高电平输入事件
function highShowBlur(val) {
  state.normalLogicList[1].name = state.formData.highShow;
}

function lowShowBlur(val) {
  state.normalLogicList[0].name = state.formData.lowShow;
}

// 校验编号是否重复
const checkIndex = (val, index, arr2) => {
  let bl = true;
  let arr = JSON.parse(JSON.stringify(arr2));
  arr.splice(index, 1);
  arr.forEach((item) => {
    if (item.childIndexId == val) {
      bl = false;
    }
  });
  if (!bl) {
    ElMessage.error("编号不能重复");
    arr2[index].childIndexId = null;
  }
};
// 检验名称是否重复
const checkName = (val) => {
  let validParamType = state.options.validParam;
  if (state.tabName == "simulate") {
    validParamType = state.options.validParam;
  } else if (state.tabName == "switch") {
    validParamType = state.options1.validParam;
  } else if (state.tabName == "add") {
    validParamType = state.options2.validParam;
  }
  if (state.editId) {
    axios
      .get(validParamType, {
        params: {
          type: 0,
          value: val,
          id: state.editId,
        },
      })
      .then((res) => {
        if (res.code == 200) {
          state.repeat2 = false;
        }
      })
      .catch((res) => {
        state.repeat2 = true;
      });
  } else {
    axios
      .get(validParamType, {
        params: {
          type: 0,
          value: val,
        },
      })
      .then((res) => {
        if (res.code == 200) {
          state.repeat2 = false;
        }
      })
      .catch((res) => {
        state.repeat2 = true;
      });
  }
};
// 检验主索引是否重复
const checkIndexId = (val) => {
  if (val == "") {
    return;
  }
  let validParamType = state.options.validParam;
  if (state.tabName == "simulate") {
    validParamType = state.options.validParam;
  } else if (state.tabName == "switch") {
    validParamType = state.options1.validParam;
  } else if (state.tabName == "add") {
    validParamType = state.options2.validParam;
  }
  if (state.editId) {
    axios
      .get(validParamType, {
        params: {
          type: 1,
          value: val,
          id: state.editId,
        },
      })
      .then((res) => {
        if (res.code == 200) {
          state.repeat = false;
        }
      })
      .catch((res) => {
        state.repeat = true;
      });
  } else {
    axios
      .get(validParamType, {
        params: {
          type: 1,
          value: val,
        },
      })
      .then((res) => {
        console.log(res);
        if (res.code == 200) {
          state.repeat = false;
        }
      })
      .catch((res) => {
        state.repeat = true;
      });
  }
};

// 量程与频率上下限输入限制
const handleInput = (item, str1, str2) => {
  if (str2) { 
    if (item[str1]*1 > item[str2]*1) {
      item[str2] = item[str1];
    }
    if (str2 == "lowScaleUp" || str2 == "highScaleUp") {
      ElMessage.warning("请填写对应量程的频率");
    }
  } else {
    if (item[str1] < 0) {
      item[str1] = "0";
    }
  }
};
</script>
<style scoped lang="scss">
.inputrange {
  background: rgba(91, 109, 128, 0.08);

  ::v-deep .el-input__wrapper {
    box-shadow: none;
    background: rgba(91, 109, 128, 0);
  }
}

.form_box {
  max-height: 580px;
  overflow: auto;
}
</style>
